﻿using SCG.General;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//SpriteFactory loads all instances of SpriteSources, and enumerates them to create a sprite for a MapObject

namespace TTEngine
{
    public static class SpriteFactory
    {
        //installation of a SpriteSource
        public static void InstallSpriteSource(SpriteSource ss)
        {
            _spriteSources.Add(ss);
            if (ss.IsPrimarySource)
                _primary = ss;
        }

        //create a sprite for a MapObject
        public static object CreateSprite(MapObject mo)
        {
            foreach (SpriteSource ss in _spriteSources)
            {
                object s = ss.CreateSprite(mo);
                if (s != null)
                    return s;
            }
            if (_primary != null)
                return _primary.CreateSpriteAsPrimarySource(mo);
            return null;
        }

        //private members
        private static List<SpriteSource> _spriteSources = new List<SpriteSource>();
        private static SpriteSource _primary = null;
    }
}
